package com.zycoin.common.plugin.mybatis.page;

import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("rawtypes")
public class Page<T>  {
    @Transient
    private int startNum= -1;//开始页数，默认是0开始
    @Transient
	private int pageSize = 10;// 每页显示的记录数，默认是10
    @Transient
	private int totalRecord=-1;// 总记录数
    @Transient
	private int totalPage;// 总页数
    @Transient
	private List<T> result = new ArrayList<T>();

    public int getStartNum() {
		return startNum;
	}

	public void setStartNum(int startNum) {
		this.startNum = startNum;
	}

	public List<T> getResult() {
		return result;
	}

	public void setResult(List<T> result) {
		this.result = result;
	}
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
		// 逢一进一分页公式：总页数 = （总条数 - 1） / 每页查询条数 + 1
		int totalPage = (totalRecord - 1) / pageSize + 1;
		this.setTotalPage(totalPage);
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Page [startNum=").append(startNum).append(", pageSize=").append(pageSize).append(", results=").append(result.toString()).append(", totalPage=").append(totalPage).append(", totalRecord=").append(totalRecord).append("]");
		return builder.toString();
	}
}
